Page({
    data: {
      showPopup: false,
      nickname: '',
      password: '',
      newPassword: ''
    },
  
    showModal: function() {
      this.setData({ showPopup: true });
    },
  
    handleNicknameInput: function(e) {
      this.setData({ nickname: e.detail.value });
    },
  
    handlePasswordInput: function(e) {
      this.setData({ password: e.detail.value });
    },
  
    handleNewPasswordInput: function(e) {
      this.setData({ newPassword: e.detail.value });
    },
  
    handleConfirm: function() {
      if (!this.data.nickname || !this.data.password || !this.data.newPassword) {
        wx.showToast({ title: '所有字段均为必填', icon: 'none' });
        return;
      } else {
          
      }
      
      if (this.data.newPassword.length < 6 || this.data.newPassword.length > 10) {
        wx.showToast({ title: '新密码长度需在6-10位之间', icon: 'none' });
        return;
      }
        console.log(this.data.nickname);
        console.log(this.data.password);
        console.log(this.data.newPassword);
      wx.request({
        url: 'http://47.95.223.130:8083/User/update',
        method: 'POST',
        header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          nickname: this.data.nickname,
          password: this.data.password,
          newPassword: this.data.newPassword
        },
        success: (res) => {
          // 根据返回数据进行相应处理
          console.log(res)
          if (res.data.code === 200) { // 确保服务器的响应数据中包含一个code字段来表示请求是否成功
            this.setData({
              account: res.data.account, // 假设账号数据在响应的account字段中
            });
            // 显示注册成功的提示
            wx.showToast({ title: '修改成功', icon: 'none' });
          } else {
            // 处理注册失败的情况
            this.setData({
                account: res.data.account, // 假设账号数据在响应的account字段中
              });
            wx.showToast({ title: '修改失败', icon: 'none' });
          }
          
        }
      });
      
      this.setData({ showPopup: false });
      
    },
  
    handleCancel: function() {
      this.setData({ showPopup: false });
    }
  });
  

//   http://47.95.223.130:8083/User/update